import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },

  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true,
  },

  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: { title: "首页", icon: "el-icon-s-home" },
      },
    ],
  },

  {
    path: "/infoVerification",
    component: Layout,
    redirect: "/infoVerification/beneficiary",
    name: "InfoVerification",
    meta: { title: "信息核验", icon: "el-icon-document" },
    children: [
      {
        path: "beneficiary",
        name: "Beneficiary",
        component: () => import("@/views/infoVerification/beneficiary.vue"),
        meta: { title: "受益所有人", icon: "el-icon-s-custom" },
      },
      {
        path: "recordSearch",
        name: "RecordSearch",
        component: () => import("@/views/infoVerification/recordSearch.vue"),
        meta: { title: "核验记录查询(义务机构)", icon: "el-icon-s-order" },
      },
      {
        path: "detail",
        name: "InfoVerificationDetail",
        component: () => import("@/views/infoVerification/detail.vue"),
        meta: { title: "核验记录详情", icon: "" },
        hidden: true,
      },
      {
        path: "backupsDeatil",
        name: "BackupsDetail",
        component: () => import("@/views/infoVerification/backupsDetail.vue"),
        meta: { title: "备案主体信息详情", icon: "" },
        hidden: true,
      },
      {
        path: "backups",
        name: "Backups",
        component: () => import("@/views/infoVerification/backups.vue"),
        meta: { title: "备案主体信息", icon: "" },
        hidden: true,
      },
    ],
  },

  {
    path: "/case",
    component: Layout,
    redirect: "/case/casesearch",
    name: "Case",
    meta: {
      title: "案例管理",
      icon: "",
    },
    children: [
      {
        path: "casesearch",
        component: () => import("@/views/caseManagement/caseSearch.vue"), // Parent router-view
        name: "CaseSearch",
        meta: { title: "案例查询",icon:'el-icon-notebook-2' },
      },
      {
        path: "casedetail",
        component: () => import("@/views/caseManagement/caseDetail.vue"),
        name: "CaseDetail",
        meta: { title: "案例报告详情" },
        hidden: true,
      },
      {
        path: "caseApply",
        component: () => import("@/views/caseManagement/caseApply.vue"),
        name: "CaseApply",
        meta: { title: "案例申请" },
        hidden: true,
      },
    ],
  },
  {
    path: "/diffreport",
    component: Layout,
    redirect: "/diffreport/index",
    name: "DiffReport",
    meta: {
      title: "差异报告管理",
      icon: "",
    },
    children: [
      {
        path: "index",
        component: () => import("@/views/diffReport/index.vue"), // Parent router-view
        name: "DiffReportIndex",
        meta: { title: "差异报告查询",icon:'el-icon-reading' },
      },
      {
        path: "detail",
        component: () => import("@/views/diffReport/detail.vue"),
        name: "DiffReportDetail",
        meta: { title: "差异报告详情" },
        hidden: true,
      },
      {
        path: "upload",
        component: () => import("@/views/diffReport/diffInfoUpload.vue"),
        name: "DiffInfoUpload",
        meta: { title: "差异报告上传" },
        hidden: true,
      },
    ],
  },

  // 404 page must be placed at the end !!!
  { path: "*", redirect: "/404", hidden: true },
];

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
